def num_total(x):
    total = 0
    x = int(x)
    while x!=0:
        total += x%10
        x = x/10
    return total

num = int(input())
a = list(map(str,input().split()))
b = []
res = {}

for i in range(num):
    res[a[i]] = num_total(a[i])
res = sorted(res.items(),  key=lambda d: d[1], reverse=True) #排序返回列表

for i in range(len(res)):
    if(int(res[i][1]) > int(res[i+1][1])):
        print(int(res[i][1]),end=' ')
    else: # 相等的情况
        j = i+1
        length = 0
        while(int(res[j][1])==int(res[i][1])): # 前一个和后一个大小比较
            length += 1
            j = j+1
        temp = res[i:j]
        temp =  sorted(temp,  key=lambda d: int(d[0]), reverse=True)
    res[i:j] = temp
    print(int(res[i][1]),end=' ')